package shop.ynubeggar.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import shop.ynubeggar.interceptor.LoginInterceptor;
import shop.ynubeggar.mapper.PointChangeMapper;
import shop.ynubeggar.model.dataobject.PointChangeDO;
import shop.ynubeggar.service.PointChangeService;

import java.util.Date;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author LiuQ
 * @since 2022-09-27
 */
@Slf4j
@Service
@DS("yeat_user")
public class PointChangeServiceImpl extends ServiceImpl<PointChangeMapper, PointChangeDO> implements PointChangeService {
    @Override
    public void add(int num) {
        long userId = LoginInterceptor.threadLocal.get().getId();
        PointChangeDO pointChangeDO = PointChangeDO.builder().userId(userId).date(new Date()).num(num).build();
        save(pointChangeDO);
    }

    @Override
    public void reduce(int num) {
        long userId = LoginInterceptor.threadLocal.get().getId();
        PointChangeDO pointChangeDO = PointChangeDO.builder().userId(userId).date(new Date()).num(-num).build();
        save(pointChangeDO);
    }
}
